home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / dev / c / MPEGAPPCdev.lha / MPEGAPPCdev / Include / libraries / mpega.h
Encoding:
C/C++ Source or Header  |  2000-07-22  |  5.3 KB  |  184 lines

  1. /*------------------------------------------------------------------------------
  2.  
  3.     File    :   MPEGA.h
  4.  
  5.     Author  :   Stéphane TAVENARD
  6.  
  7.     $VER:   MPEGA.h  2.0  (21/06/1998)
  8.  
  9.     (C) Copyright 1997-1998 Stéphane TAVENARD
  10.         All Rights Reserved
  11.  
  12.     #Rev|   Date   |                      Comment
  13.     ----|----------|--------------------------------------------------------
  14.     0   |25/10/1997| Initial revision                                     ST
  15.     1   |21/06/1998| Added MPEGA_scale                                    ST
  16.  
  17.     ------------------------------------------------------------------------
  18.  
  19.     MPEGA decoder library definitions
  20.  
  21. ------------------------------------------------------------------------------*/
  22.  
  23. #ifndef LIBRARIES_MPEGA_H
  24. #define LIBRARIES_MPEGA_H
  25.  
  26. #define MPEGA_VERSION 2 /* #1 */
  27.  
  28. #ifndef EXEC_TYPES_H
  29. #include <exec/types.h>
  30. #endif
  31.  
  32. #ifndef UTILITY_HOOKS_H
  33. #include <utility/hooks.h>
  34. #endif
  35.  
  36. /* Controls for decoding */
  37.  
  38. /* Qualities */
  39. #define MPEGA_QUALITY_LOW    0
  40. #define MPEGA_QUALITY_MEDIUM 1
  41. #define MPEGA_QUALITY_HIGH   2
  42.  
  43. /*
  44.    Bitstream Hook function is called like (SAS/C syntax):
  45.  
  46.  
  47.    ULONG __saveds __asm HookFunc( register __a0 struct Hook  *hook,
  48.                                   register __a2 APTR          handle,
  49.                                   register __a1 MPEGA_ACCESS *access );
  50.  
  51.    MPEGA_ACCESS struct specify bitstream access function & parameters
  52.  
  53.    access->func == MPEGA_BSFUNC_OPEN
  54.       open the bitstream
  55.       access->data.open.buffer_size is the i/o block size your read function can use
  56.       access->data.open.stream_size is the total size of the current stream
  57.                                     (in bytes, set it to 0 if unknown)
  58.       return your file handle (or NULL if failed)
  59.    access->func == MPEGA_BSFUNC_CLOSE
  60.       close the bitstream
  61.       return 0 if ok
  62.    access->func == MPEGA_BSFUNC_READ
  63.       read bytes from bitstream.
  64.       access->data.read.buffer is the destination buffer.
  65.       access->data.read.num_bytes is the number of bytes requested for read.
  66.       return # of bytes read or 0 if EOF.
  67.    access->func == MPEGA_BSFUNC_SEEK
  68.       seek into the bitstream
  69.       access->data.seek.abs_byte_seek_pos is the absolute byte position to reach.
  70.       return 0 if ok
  71. */
  72.  
  73. #define MPEGA_BSFUNC_OPEN  0
  74. #define MPEGA_BSFUNC_CLOSE 1
  75. #define MPEGA_BSFUNC_READ  2
  76. #define MPEGA_BSFUNC_SEEK  3
  77.  
  78. typedef struct {
  79.  
  80.    LONG  func;           /* MPEGA_BSFUNC_xxx */
  81.    union {
  82.       struct {
  83.          char *stream_name; /* in */
  84.          LONG buffer_size;  /* in */
  85.          LONG stream_size;  /* out */
  86.       } open;
  87.       struct {
  88.          void *buffer;      /* in/out */
  89.          LONG num_bytes;    /* in */
  90.       } read;
  91.       struct {
  92.          LONG abs_byte_seek_pos; /* out */
  93.       } seek;
  94.    } data;
  95.  
  96. } MPEGA_ACCESS;
  97.  
  98. /* Decoding output settings */
  99.  
  100. typedef struct
  101. #ifdef __GNUC__
  102. __attribute__((aligned(2),packed))
  103. #endif
  104. {
  105.    WORD freq_div;    /* 1, 2 or 4 */
  106.    WORD quality;     /* 0 (low) .. 2 (high) */
  107.    LONG freq_max;    /* for automatic freq_div (if mono_freq_div == 0) */
  108. } MPEGA_OUTPUT;
  109.  
  110. /* Decoding layer settings */
  111.  
  112. typedef struct
  113. #ifdef __GNUC__
  114. __attribute__((aligned(2),packed))
  115. #endif
  116. {
  117.    WORD force_mono;        /* 1 to decode stereo stream in mono, 0 otherwise */
  118.    MPEGA_OUTPUT mono;      /* mono settings */
  119.    MPEGA_OUTPUT stereo;    /* stereo settings */
  120. } MPEGA_LAYER;
  121.  
  122. /* Full control structure of MPEG Audio decoding */
  123.  
  124. typedef struct
  125. #ifdef __GNUC__
  126. __attribute__((aligned(2),packed))
  127. #endif
  128. {
  129.    struct Hook *bs_access;    /* NULL for default access (file I/O) or give your own bitstream access */
  130.    MPEGA_LAYER layer_1_2;     /* Layer I & II settings */
  131.    MPEGA_LAYER layer_3;       /* Layer III settings */
  132.    WORD check_mpeg;           /* 1 to check for mpeg audio validity at start of stream, 0 otherwise */
  133.    LONG stream_buffer_size;   /* size of bitstream buffer in bytes (0 -> default size) */
  134.                               /* NOTE: stream_buffer_size must be multiple of 4 bytes */
  135. } MPEGA_CTRL;
  136.  
  137. /* MPEG Audio modes */
  138.  
  139. #define MPEGA_MODE_STEREO   0
  140. #define MPEGA_MODE_J_STEREO 1
  141. #define MPEGA_MODE_DUAL     2
  142. #define MPEGA_MODE_MONO     3
  143.  
  144. typedef struct
  145. #ifdef __GNUC__
  146. __attribute__((aligned(2),packed))
  147. #endif
  148. {
  149.    /* Public data (read only) */
  150.    /* Stream info */
  151.    WORD  norm;          /* 1 or 2 */
  152.    WORD  layer;         /* 1..3 */
  153.    WORD  mode;          /* 0..3  (MPEGA_MODE_xxx) */
  154.    WORD  bitrate;       /* in kbps */
  155.    LONG  frequency;     /* in Hz */
  156.    WORD  channels;      /* 1 or 2 */
  157.    ULONG ms_duration;   /* stream duration in ms */
  158.    WORD  private_bit;   /* 0 or 1 */
  159.    WORD  copyright;     /* 0 or 1 */
  160.    WORD  original;      /* 0 or 1 */
  161.    /* Decoding info according to MPEG control */
  162.    WORD  dec_channels;  /* decoded channels 1 or 2 */
  163.    WORD  dec_quality;   /* decoding quality 0..2 */
  164.    LONG  dec_frequency; /* decoding frequency in Hz */
  165.  
  166.    /* Private data */
  167.    void  *handle;
  168. } MPEGA_STREAM;
  169.  
  170. #define MPEGA_MAX_CHANNELS 2    // Max channels
  171. #define MPEGA_PCM_SIZE     1152 // Max samples per frame
  172.  
  173. /* Error codes */
  174.  
  175. #define MPEGA_ERR_NONE     0
  176. #define MPEGA_ERR_BASE     0
  177. #define MPEGA_ERR_EOF      (MPEGA_ERR_BASE-1)
  178. #define MPEGA_ERR_BADFRAME (MPEGA_ERR_BASE-2)
  179. #define MPEGA_ERR_MEM      (MPEGA_ERR_BASE-3)
  180. #define MPEGA_ERR_NO_SYNC  (MPEGA_ERR_BASE-4)
  181. #define MPEGA_ERR_BADVALUE (MPEGA_ERR_BASE-5) /* #1 */
  182.  
  183. #endif /* LIBRARIES_MPEGA_H */
  184.